import { createApp } from 'vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { createPinia } from 'pinia'
import piniaPlugin from './store/plugin'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import '@/style/reset.css'
import '@/assets/icon-font/iconfont.css'
import '@/assets/icon-font/iconfont.js'
import App from './App.vue'
const store = createPinia()
store.use(piniaPlugin({
    key: "store"
}))
const app = createApp(App)
app.use(router)


app.use(store)
app.use(ElementPlus)
//element-icon
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.mount('#app')
//挂载路由导航守卫
router.beforeEach((to, from, next) => {
    if(!localStorage.getItem('admin-token')) {
        if (to.path === '/login') {
            next()
        } else {
            next('/login')
        }
    } else {
        if (to.path === '/login') {
            next('/')
        } else {
            next()
        }
    }
})
